import React, {Component} from 'react';
import './Header.css'

class Header extends Component {
    // 键盘时间回调
    enterSave = (event) => {
        // 判断是否是回车按键事件
        if (event.keyCode !== 13) return
        if (event.target.value.trim() === '') {
            alert("input not null")
            return
        }
        const newTodo = {id: new Date().getTime(), name: event.target.value, done: false}
        // 将输入的值传递给父组件
        this.props.addTodo(newTodo)
        // 情况输入
         event.target.value = '';
    }

    render() {
        return (
            <div className="todo-header">
                <input type="text" onKeyUp={this.enterSave}
                       placeholder="Please enter the task name and press Enter to confirm"/>
            </div>
        );
    }
}

export default Header;